* **************************************************************************** *
* Sierra Leone - Social Signaling and Childhood Immunization
* Verifying the Correct Implementation of Bracelets, Regression Results
* **************************************************************************** *
/*
** Purpose:  Create Table: Verifying the Correct Implementation of Bracelets, 
				Regression Results for Figure on correct implementation

*/
* **************************************************************************** *
* **************************************************************************** *


	* ----------------------------------------------------------------------------
	* Generate Regression Table:

	use  "${Replicate_SocialSignals_dtaFinal}/Listing_Data_BraceletHandout.dta", clear


	* Demean ANC Indicator:
	tab     arm_anc, gen(anc)

	foreach treatArm of numlist 3 4 2 {
		foreach var in  anc2 anc3 anc4  {
			sum    `var'                                 if intervention_arm==`treatArm'
			gen    `var'_arm`treatArm'_dm    = `var' - `r(mean)'    if intervention_arm==`treatArm'
		}
	}


	summ   anc2_arm2_dm anc3_arm2_dm anc4_arm2_dm yellow green    if intervention_arm == 2
	summ   anc2_arm3_dm anc3_arm3_dm anc4_arm3_dm yellow green    if intervention_arm == 3
	summ   anc2_arm4_dm anc3_arm4_dm anc4_arm4_dm yellow green    if intervention_arm == 4



	** Regenerate table:
	eststo clear
	foreach treatArm of numlist 3 4 2 {
		areg     green vac_num2 vac_num3 vac_num4 vac_num5      anc2_arm`treatArm'_dm anc3_arm`treatArm'_dm anc4_arm`treatArm'_dm    if intervention_arm==`treatArm', absorb(strata) cluster(clinic)
		eststo modelG`treatArm'
		test   vac_num3 = vac_num4
		estadd scalar vacnum34 = r(p)
		test   vac_num4 = vac_num5
		estadd scalar vacnum45 = r(p)
		estadd scalar C_mean            = _b[_cons]
		estadd local Obs                = "`e(N)'"


		areg     yellow vac_num2 vac_num3 vac_num4 vac_num5     anc2_arm`treatArm'_dm anc3_arm`treatArm'_dm anc4_arm`treatArm'_dm     if intervention_arm==`treatArm', absorb(strata) cluster(clinic)
		eststo modelY`treatArm'
		test   vac_num3 = vac_num4
		estadd scalar vacnum34 = r(p)
		test   vac_num4 = vac_num5
		estadd scalar vacnum45 = r(p)
		estadd scalar C_mean            = _b[_cons]
		estadd local Obs                = "`e(N)'"

	}

	esttab  ///
	modelG3  modelY3         ///
	modelG4  modelY4        ///
	modelG2  modelY2        ///
	using "${Replicate_SocialSignals_ATables}/Table_CorrectBraceletImplementation_raw.tex",  ///
	prehead("\begin{tabular}{l*{7}{c}} \toprule "                       ///
	"\multicolumn{1}{l}{\textbf{Dependent variable:}} & \multicolumn{2}{c}{\textbf{Signal at 4}} & \multicolumn{2}{c}{\textbf{Signal at 5}}  & \multicolumn{2}{c}{\textbf{Uninformative Bracelet}} \\" ///
	"& \multicolumn{1}{c}{\textbf{Green}}  & \multicolumn{1}{c}{\textbf{Yellow}} & \multicolumn{1}{c}{\textbf{Green}}  & \multicolumn{1}{c}{\textbf{Yellow}}  & \multicolumn{1}{c}{\textbf{Green}}  & \multicolumn{1}{c}{\textbf{Yellow}}  \\") ///
	scalars("C_mean      Mean Vaccine 1 "                               ///
	"vacnum34    p(Vaccine 3 = Vaccine 4)"                      ///
	"vacnum45    p(Vaccine 4 = Vaccine 5)"                      ///
	"Obs         Observations")                                 ///
	sfmt(3) b(3) se(3)  ${StarsOpt}                                     ///
	drop(_cons  *_dm)                                                   ///
	nomtitles                                                           ///
	addnotes("") label se  nobaselevels noconstant noobs nolines        ///
	posthead("\midrule") postfoot("\bottomrule \end{tabular}") tex      ///
	replace

	filefilter "${Replicate_SocialSignals_ATables}/Table_CorrectBraceletImplementation_raw.tex"             ///
	"${Replicate_SocialSignals_ATables}/Table_CorrectBraceletImplementation.tex", from("[1em]") to(" ") replace
	erase	     "${Replicate_SocialSignals_ATables}/Table_CorrectBraceletImplementation_raw.tex"





* **************************************************************************** *
* End of the Do file !!!
* **************************************************************************** *
